/***************************************************************************
 *
 * File name: q3.c
 *
 * Author:  Tomer Filiba
 *          03701307-5
 *          sebulba@t2
 *
 *
 * Exercise #: 2
 * Question #: 3
 *
 * Submission Date: 11/6
 *
 **************************************************************************/

/*-------------------------------------------------------------------------
  Include files:
--------------------------------------------------------------------------*/
#include <stdio.h>


/*=========================================================================
  Constants and definitions:
==========================================================================*/
#define GREAT_SUCCESS		(0)
#define I_WILL_BE_EXECUTE	(1)
#define DAYS_PER_MONTH		(29.5)	
#define MONTHS_PER_YEAR		(12)
#define DAYS_PER_YEAR		(MONTHS_PER_YEAR * DAYS_PER_MONTH)



/*-------------------------------------------------------------------------
  The main program: read two muslim dates from the user and display the 
  number of days between them
 -------------------------------------------------------------------------*/
int main3(int argc, const char ** argv)
{
	int day1, month1, year1;
	int day2, month2, year2;
	double d1, d2;
	
	/* get input from user. we assume that the day-of-month
	 * and month-of-year are in the valid range valid range */
	printf("First date: ");
	if (scanf("%d/%d/%d", &day1, &month1, &year1) != 3) {
		printf("Error! Invalid format\n");
		return I_WILL_BE_EXECUTE;
	}
	
	printf("Second date: ");
	if (scanf("%d/%d/%d", &day2, &month2, &year2) != 3) {
		printf("Error! Invalid format\n");
		return I_WILL_BE_EXECUTE;
	}
	
	/* convert dates to days-from-epoch */
	d1 = day1 + month1 * DAYS_PER_MONTH + year1 * DAYS_PER_YEAR;
	d2 = day2 + month2 * DAYS_PER_MONTH + year2 * DAYS_PER_YEAR;
	
	/* check first date precedes second one */
	if (d1 > d2) {
		printf("Error! The first date must be earlier\n");
		return I_WILL_BE_EXECUTE;
	}

	/* print timespan */
	printf("Number of days in timespan: %.1f\n", d2 - d1);
	return GREAT_SUCCESS;
}


/**************************************************************************
			                          End of file
***************************************************************************/